#from demo.Minist_cnn import *
import numpy as np
import keras
from flask import Flask, escape, request
import matplotlib.image as mp
import tensorflow as tf

# 每个图像都映射到一个标签
class_names = ['T恤/上衣', '裤子', '套衫', '连衣裙', '外套',
               '凉鞋', '衬衫', '运动鞋', '包/袋', '脚踝靴']
# 设置中文显示，防止中文显示乱码
from pylab import mpl

app = Flask(__name__)

mpl.rcParams['font.sans-serif'] = ['FangSong']  # 指定默认字体
mpl.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题


graph = tf.get_default_graph()
new_model = keras.models.load_model('listm.h5')


@app.route('/test1', methods=['GET', 'POST'])
def findClassLabel():
    global graph
    file = request.files.get('file')
    img = mp.imread(file)
    print(img)
    img = (np.expand_dims(img, 2))
    img = (np.expand_dims(img, 0))
    with graph.as_default():
        predictions_single = new_model.predict(img)
    label = np.argmax(predictions_single[0])
    print(class_names[label])
    return str(class_names[label])


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)


